In [1]:
import pandas as pd
In [2]:
ds1 = pd.Series([1, 2, 3, 4], index=['a', 'b', 'c', 'd'])
ds1
Out[2]:
a    1
b    2
c    3
d    4
dtype: int64
In [3]:
ds2 = pd.Series([1, 2, 3, 4])
ds2
Out[3]:
0    1
1    2
2    3
3    4
dtype: int64
In [4]:
print(ds1['b'], ds1.d)
2 4
In [9]:
ds1[2]
Out[9]:
3
In [10]:
ds1[ ['a', 'd'] ]
Out[10]:
a    1
d    4
dtype: int64
In [11]:
ds1
Out[11]:
a    1
b    2
c    3
d    4
dtype: int64
In [12]:
ds1['d'] = 5
ds1
Out[12]:
a    1
b    2
c    3
d    5
dtype: int64
In [13]:
ds1.e = 6
ds1
Out[13]:
a    1
b    2
c    3
d    5
dtype: int64
In [14]:
ds1['e'] = 6
ds1
Out[14]:
a    1
b    2
c    3
d    5
e    6
dtype: int64
In [15]:
ds1.at['f'] = 7
ds1
Out[15]:
a    1
b    2
c    3
d    5
e    6
f    7
dtype: int64
In [16]:
ds1[ ['d', 'e', 'f'] ] = [4, 5, 6]
ds1
Out[16]:
a    1
b    2
c    3
d    4
e    5
f    6
dtype: int64
In [17]:
ds2
Out[17]:
0    1
1    2
2    3
3    4
dtype: int64
In [18]:
ds1.at['g'] = 10.5
ds1
Out[18]:
a     1.0
b     2.0
c     3.0
d     4.0
e     5.0
f     6.0
g    10.5
dtype: float64
In [21]:
ds2[1]
Out[21]:
2
In [22]:
ds2.at[1]
Out[22]:
2
In [23]:
ds2.iat[1]
Out[23]:
2
In [26]:
ds2 = ds2 * 2
In [27]:
ds2
Out[27]:
0    2
1    4
2    6
3    8
dtype: int64
In [28]:
l = [1, 2, 3, 4]
l
Out[28]:
[1, 2, 3, 4]
In [29]:
l * 2
Out[29]:
[1, 2, 3, 4, 1, 2, 3, 4]
In [30]:
cities = pd.Series({'Dnepr': 1000000, 'Kiev': 3000000, 'Paris': 2300000, 'Berlin': 3800000})
cities
Out[30]:
Dnepr     1000000
Kiev      3000000
Paris     2300000
Berlin    3800000
dtype: int64
In [32]:
cities2 = pd.Series(
    {'Dnepr': 1000000, 'Kiev': 3000000, 'Paris': 2300000, 'Berlin': 3800000},
    index=['Dnepr', 'Paris', 'Berlin', 'Milan']
)
cities2
Out[32]:
Dnepr     1000000.0
Paris     2300000.0
Berlin    3800000.0
Milan           NaN
dtype: float64
In [33]:
test = pd.Series([1, 2, 3], index=['a', 'b', 'c'])
test2 = pd.Series([4, 5, 6, 7], index=['a', 'b', 'c', 'd'])
In [34]:
test + test2
Out[34]:
a    5.0
b    7.0
c    9.0
d    NaN
dtype: float64
In [37]:
test.add(test2, fill_value=0)
Out[37]:
a    5.0
b    7.0
c    9.0
d    7.0
dtype: float64
In [ ]: